package com.sinoeyes.controller.flowdata;

import com.sinoeyes.common.core.controller.BaseController;
import com.sinoeyes.common.core.page.RestPageResult;
import com.sinoeyes.common.result.RCode;
import com.sinoeyes.common.result.Result;
import com.sinoeyes.common.utils.bean.ObjectUtils;
import com.sinoeyes.flowdata.filter.FlowSalesDataFilter;
import com.sinoeyes.flowdata.service.IFlowSalesDataService;
import com.sinoeyes.flowdata.vo.FlowSalesDatasVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 标准销售流向Controller
 * 
 * @author steven.zhang
 * @date 2019-10-10
 */
@Api(value = "FlowData Sales API", tags = {"标准销售流向接口"})
@RestController
@RequestMapping("/flowdata/sales")
public class IFlowSalesDatasController extends BaseController{

    @Autowired
    private IFlowSalesDataService flowSalesDatasService;

    @ResponseBody
    @ApiOperation("获取单条流向数据信息")
    @ApiImplicitParam(name = "id", value = "流向数据ID", required = true, dataType = "String", paramType = "path")
    @GetMapping("/getFlowSalesDatasById/{id}")
    public Result<FlowSalesDatasVo> getFlowSalesDatasById(@PathVariable String id) {
        FlowSalesDatasVo flowSalesDatasVo = flowSalesDatasService.selectFlowSalesDatasById(id);
        if (ObjectUtils.isNotEmpty(flowSalesDatasVo)) {
            return Result.success(flowSalesDatasVo);
        }
        return Result.failure(RCode.NO_QUERY);
    }

    @ResponseBody
    @ApiOperation("获取流向数据列表")
    @ApiImplicitParams({ @ApiImplicitParam(paramType = "body", dataType = "FlowSalesDataFilter", name = "flowSalesDataFilter", value = "查询过滤器", required = false) })
    @PostMapping("/getFlowSalesDatasByFilter")
    public Result<RestPageResult<FlowSalesDatasVo>> getFlowSalesDatasByFilter(@RequestBody(required = false) FlowSalesDataFilter flowSalesDataFilter) {
        RestPageResult<FlowSalesDatasVo> pageResult = flowSalesDatasService.selectFlowSalesDatasByFilter(flowSalesDataFilter);
        if (pageResult != null) {
            return Result.success(pageResult);
        }
        return Result.failure(RCode.NO_QUERY);
    }
}
